﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace XNA
{
    public class MySprite
    {
        private Texture2D[] _texture2ds;
        private int _ntexture2ds;
        private int _itexture2d;
        private Vector2 _position;

        public int itexture2D
        {
            get { return _itexture2d; }
            set { _itexture2d = value; }
        }

        public Vector2 position
        {
            get { return _position; }
            set { _position = value; }
        }

        public int ntexture2Ds
        {
            get { return _ntexture2ds; }
            set { _ntexture2ds = value; }
        }

        public Texture2D[] texture2Ds
        {
            get { return _texture2ds; }
            set
            {
                _texture2ds = value;
                _ntexture2ds = _texture2ds.Length;
                _itexture2d = 0;
            }
        }

        public float normalDelay
        {
            get { return _normalDelay; }
            set { _normalDelay = value; }
        }

        //Updating with Fixed Timing
        private float _normalDelay = 16.0f;

        public MySprite(Texture2D[] texture2ds, Vector2 pos)
        {
            texture2Ds = texture2ds;
            position = pos;
        }

        public void Update(GameTime gameTime)
        {
            int delta = (int)(gameTime.TotalGameTime.Milliseconds/normalDelay);
            _itexture2d = (_itexture2d + delta)%_ntexture2ds;
        }
        
        public void Draw(GameTime gameTime, SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(_texture2ds[_itexture2d], position, Color.White);
        }
    }
}
